<?php
namespace App\Controllers\Passport;
class Regist extends \App\Libs\Base\BaseAction
{
    protected function beforeRun() {
        parent::beforeRun();
    }

	protected function execute() {
		$fields = array('phone', 'password', 'nickname', 'avatar', 'longitude', 'latitude');
		$infos = array();
		foreach ($fields as $field) {
			$infos[$field] = $this->request->get($field);
		}
		// avatar base 64
		$user = new \App\Models\User\User();
		$id = $user->regist($infos);
		if ($id > 0) {
			// insert into 
		}
		$data = array(
						'token' => $user->token,
						'name' => $user->nickname,
						'avatar' => $user->avatar,
					 );
		return \App\Libs\Views\Json::view(0, 'ok', $data);	
	}

	protected function saveAvatar($base64) {
		$image = new \App\Models\Image\Image();
		$res = $image->saveBase64($base64);
		if (!$res) return '';
		return $res['uri'];
	}

}
